function ajaxEx(url, requestData, cbSuccess, cbError) {
    $.ajax({
        url: url,
        type: "POST",
        data: requestData,
        success: function (data) {
            if (data.code === code.INVALID_UERS) {

                window.parent.window.location.href = '/webs';
                return;
            }
            if (data.code !== 0) {
                // alert("错误：" + code[data.code]);
                let message = code[data.code];
                Swal.fire(message);
                invokeCallback(cbError, data);
            } else {
                invokeCallback(cbSuccess, data);
            }
        },
        error: function () {
            // alert("请求错误");
            $.modal({ body: '请求错误' });
            invokeCallback(cbError, { code: 1 });
        }
    });
}

// -------------------------------------管理员帐号相关-----------------------------------
function apiAdminLogin(account, password, cbSuccess, cbFail) {
    let data = {
        account: account,
        password: password
    };
    ajaxEx("/login", data, cbSuccess, cbFail);
}

function apiAdminLogout(cbSuccess, cbFail) {
    let data = {
    };
    ajaxEx("/logout", data, cbSuccess, cbFail);
}

function apiUpdateAdminPassword(password, cbSuccess, cbFail) {
    let data = {
        password: password
    };
    ajaxEx("/admin/updateAdminPassword", data, cbSuccess, cbFail);
}
// -------------------------------------记录相关-----------------------------------
function apiRetransmissionToGameServer(data, cbSuccess, cbFail) {
    ajaxEx("/admin/retransmissionToGameServer", data, cbSuccess, cbFail);
}

function apiAdminGetRecord(model, startIndex, count, matchData, cbSuccess, cbFail) {
    let data = {
        model: model,
        startIndex: startIndex,
        count: count,
        matchData: JSON.stringify(matchData)
    };
    ajaxEx("/admin/getRecord", data, cbSuccess, cbFail);
}

function apiAdminGetUnion(model, startIndex, count, matchData, cbSuccess, cbFail) {
    let data = {
        model: model,
        startIndex: startIndex,
        count: count,
        matchData: JSON.stringify(matchData)
    };
    ajaxEx("/admin/getUnion", data, cbSuccess, cbFail);
}

function apiAdminUpdateRecord(model, matchData, saveData, cbSuccess, cbFail) {
    let data = {
        model: model,
        saveData: JSON.stringify(saveData),
        matchData: JSON.stringify(matchData)
    };
    ajaxEx("/admin/updateRecord", data, cbSuccess, cbFail);
}

function apiAdminAddRecord(model, saveData, cbSuccess, cbFail) {
    let data = {
        model: model,
        saveData: JSON.stringify(saveData)
    };
    ajaxEx("/admin/addRecord", data, cbSuccess, cbFail);
}

function apiAdminDeleteRecord(model, matchData, cbSuccess, cbFail) {
    let data = {
        model: model,
        matchData: JSON.stringify(matchData)
    };
    ajaxEx("/admin/deleteRecord", data, cbSuccess, cbFail);
}

// -------------------------------------用户管理相关-----------------------------------
function apiAdminGrant(field, uid, count, cbSuccess, cbFail) {
    let data = {
        field: field,
        uid: uid,
        count: count
    };
    ajaxEx("/admin/grant", data, cbSuccess, cbFail);
}

function apiGetOnlineUserData(startIndex, count, uid, cbSuccess, cbFail) {
    let data = {
        startIndex: startIndex,
        count: count,
        uid: uid
    };
    ajaxEx("/admin/getOnlineUserData", data, cbSuccess, cbFail);
}

function apiUpdateUserData(uid, saveData, cbSuccess, cbFail) {
    let data = {
        uid: uid,
        saveData: JSON.stringify(saveData)
    };
    ajaxEx("/admin/updateUserData", data, cbSuccess, cbFail);
}

function apiUpdateUserTest(uid, saveData, cbSuccess, cbFail) {
    let data = {
        uid: uid,
        saveData: JSON.stringify(saveData)
    };
    ajaxEx("/admin/updateUserTest", data, cbSuccess, cbFail);
}

function apiUpdateUserDataEx(matchData, saveData, cbSuccess, cbFail) {
    let data = {
        matchData: JSON.stringify(matchData),
        saveData: JSON.stringify(saveData)
    };
    ajaxEx("/admin/updateUserDataEx", data, cbSuccess, cbFail);
}


// -------------------------------------系统管理相关-----------------------------------
function apiSendSingleEmail(uid, title, content, cbSuccess, cbFail) {
    let data = {
        uid: uid,
        title: title,
        content: content
    };
    ajaxEx("/admin/sendSingleEmail", data, cbSuccess, cbFail);
}

function apiSendAllServerEmail(title, content, cbSuccess, cbFail) {
    let data = {
        title: title,
        content: content
    };
    ajaxEx("/admin/sendAllServerEmail", data, cbSuccess, cbFail);
}
// -------------------------------------游戏控制相关-----------------------------------
function apiModifyInventoryValue(kind, count, cbSuccess, cbFail) {
    let data = {
        kind: kind,
        count: count
    };
    ajaxEx("/admin/modifyInventoryValue", data, cbSuccess, cbFail);
}

// -------------------------------------数据相关--------------------------------------
function apiGetRechargeStatisticsInfoGroupByDay(matchData, cbSuccess, cbFail) {
    let data = {
        matchData: JSON.stringify(matchData)
    };
    ajaxEx("/admin/getRechargeStatisticsInfoGroupByDay", data, cbSuccess, cbFail);
}

function apiGetRecordStatisticsInfo(startTime, endTime, cbSuccess, cbFail) {
    let data = {
        startTime: startTime,
        endTime: endTime
    };
    ajaxEx("/admin/getRecordStatisticsInfo", data, cbSuccess, cbFail);
}

function apiAdminUpdateUnionRecord(matchData, saveData, unionID, cbSuccess, cbFail) {
    let data = {
        saveData: JSON.stringify(saveData),
        matchData: JSON.stringify(matchData),
        unionID: unionID
    };
    ajaxEx("/admin/updateUnionData", data, cbSuccess, cbFail);
}

function apiDeleteUnion(unionID, cbSuccess, cbFail) {
    let data = {
        unionID: unionID
    };
    ajaxEx("/admin/deleteUnion", data, cbSuccess, cbFail);
}

//机器人相关
function addNewRobot(data, cbSuccess, cbFail) {

    ajaxEx("/robot/addNew", data, cbSuccess, cbFail);

}

function apiBandAccount(uid, account, password, cbSuccess, cbFail) {

    let data = { uid, account, password };
    ajaxEx("/admin/bandaccount", data, cbSuccess, cbFail);
}

function apiAddAccount(account, password, nickname, cbSuccess, cbFail) {

    let data = { nickname, account, password };
    ajaxEx("/admin/addaccount", data, cbSuccess, cbFail);
}

function apiRobotBand(uid, isBind, cbSuccess, cbFail) {

    let data = { uid, isBind };
    ajaxEx("/robot/band", data, cbSuccess, cbFail);
}

//机器人回收
function apiRebackRobot(uid, cbSuccess, cbFail) {
    let data = { uid };
    ajaxEx("/robot/reback", data, cbSuccess, cbFail);

}

//投放机器人
function apiRobotToUnion(uid, unionID, cbSuccess, cbFail) {
    let data = { uid, unionID };
    ajaxEx("/robot/readd", data, cbSuccess, cbFail);

}


//投放机器人
function apiReGameType(uid, updateInfo, cbSuccess, cbFail) {
    let data = { uid, updateInfo };
    ajaxEx("/robot/retype", data, cbSuccess, cbFail);

}

//联盟推送
function apiUnionSetMain(unionID, isMain, cbSuccess, cbFail) {
    let data = { isMain, unionID };
    ajaxEx("/admin/union/setmian", data, cbSuccess, cbFail);

}

function getMainData(cbSuccess, cbFail) {
    ajaxEx("/admin/mainData", {}, cbSuccess, cbFail);

}


function getHeiBaiUser(userType, uid, startIndex, count, cbSuccess, cbFail) {

    let data = {
        userType, uid, startIndex, count,
    }
    ajaxEx("/admin/getHeiBaiUser", data, cbSuccess, cbFail);

}




